package com.summer.content.api;

import com.summer.content.service.CourseTeacherService;
import com.summer.pojo.CourseTeacher;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "师资管理API")
@RestController
@Slf4j
public class TeacherController {

    @Autowired
    private CourseTeacherService courseTeacherService;

    @ApiOperation(value = "查询所有教师")
    @GetMapping("courseTeacher/list/{courseId}")
    List<CourseTeacher> listByCourseId(@PathVariable Long courseId){
        log.info("根据courseid查询所有教师， courseid = {}", courseId);
        return courseTeacherService.getListByCourseId(courseId);
    }

    @ApiOperation(value = "添加或修改教师")
    @PostMapping("courseTeacher")
    public CourseTeacher addTeacher(@RequestBody @Validated CourseTeacher courseTeacher){
        log.info("添加或修改教师，请求参数addTeacherDto = {}", courseTeacher);
        return courseTeacherService.saveTeacher(courseTeacher);
    }

    @ApiOperation(value = "删除教师")
    @DeleteMapping("courseTeacher/course/{courseId}/{id}")
    public void deleteTeacher(@PathVariable Long courseId, @PathVariable Long id){
        courseTeacherService.deleteTeacher(courseId, id);
    }

}
